<template>
  <div>
    <!-- 面包屑导航条 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/toOneList' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>数据中心</el-breadcrumb-item>
      <el-breadcrumb-item>客户管理管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!--上传-->
    <el-dialog title="导入文件" :visible.sync="importMaterBom">
      <el-upload
        class="upload-demo"
        drag
        action='/api/customer/imporExcel'
        :on-success="updateMater"
        multiple>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip" slot="tip">只能上传excel文件</div>
      </el-upload>
    </el-dialog>
    <!-- 卡片视图 -->
    <el-card class="box-card2">
      <!--模糊查询-->
      <el-form :model="searchForm" class="demo-form-inline" >
        <el-row :gutter="20">
          <el-form-item>
            <el-col :span="4">
              <el-input placeholder="客户姓名" v-model="searchForm.name"></el-input>
            </el-col>
            <el-button @click="searchList" plain type="info" class="btn"  icon="el-icon-search">搜索</el-button>
            <el-button @click="toAdd()" type="primary">添加客户</el-button>
            <el-button @click="toLink()" type="primary">添加联系人</el-button>
            <el-button @click="importMaterBom=true" type="info" class="btn"><i class="el-icon-upload2 el-icon--right"></i>导入</el-button>
            <el-button @click="exportExcle" type="info" class="btn"><i class="el-icon-download el-icon--right"></i>导出</el-button>
          </el-form-item>
        </el-row>
      </el-form>
    </el-card>

    <el-card class="box-card">
      <el-table
        :data="customerList"
        stripe
        style="width: 100%">
        <el-table-column
          label="编号"
          prop="code">
        </el-table-column>
        <el-table-column
          label="姓名"
          prop="name">
        </el-table-column>
        <el-table-column
          label="发票类型"
          prop="invoiceType">
          <template slot-scope="scope">
            {{scope.row.invoiceType|invoiceTypeFilert}}
          </template>
        </el-table-column>
        <el-table-column
          label="发票抬头"
          prop="invoiceTitle">
        </el-table-column>
        <el-table-column
          label="税号"
          prop="invoiceNum">
        </el-table-column>
        <el-table-column
          label="税率"
          prop="taxRate">
        </el-table-column>
        <el-table-column
          label="公司地址"
          prop="address">
        </el-table-column>
        <el-table-column
          label="所属行业"
          prop="industry">
          <template slot-scope="scope">
            {{scope.row.industry | industryFilter}}
          </template>
        </el-table-column>
        <el-table-column
          label="首次合作时间"
          prop="hiredate">
          <template slot-scope="scope">
            {{scope.row.cooperDate |formatDate}}
          </template>
        </el-table-column>
        <el-table-column
          label="描述"
          prop="remarks">
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作">
          <template slot-scope="scope">
            <el-popover placement="right" width="200" trigger="click">
              <el-button @click="getlinkman(scope.row)" type="success"><i class="el-icon-search" plain></i></el-button><!--查看联系人-->
              <el-button @click="del(scope.row)" type="danger"><i class="el-icon-delete" circle></i></el-button><!--删除按钮-->
              <el-button @click="getCustomer(scope.row)" type="primary"><i class="el-icon-edit" circle></i></el-button><!--编辑按钮-->
              <el-button slot="reference" type="text">更多操作</el-button>
            </el-popover>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page.pagenum"
        :page-size="page.pagesize"
        :page-sizes="[5, 10, 20, 40]"
        :total="total"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>

    </el-card>
  </div>
</template>

<script>
    export default {
        name: "Customer",
      data() {
        return {
          importMaterBom:false,
          customerList:[],
          searchForm:{},
          linkmanform:[],
          page: {
            pagenum: 0,
            pagesize: 5
          },
          total: 0,
        }
        },
      filters:{
        invoiceTypeFilert:function (val) {
          if(val==0){
            return"增值税普通发票";
          }
          if(val==1){
            return"增值税专用发票";
          }
        },
        industryFilter:function (val) {
          if(val==0){
            return"机械制造";
          }
          if(val==1){
            return"房地产";
          }
          if(val==2){
            return"金融";
          }
          if(val==3){
            return"教育";
          }
        },
      },
      methods: {
        exportExcle:function () {//导出
          location.href="http://localhost:8080/customer/exportExcle";
        },
        updateMater:function(){//导入
          this.searchList()
        },
        toLink(){//组件跳转到联系人添加页面
          this.$router.push('/LinkAdd');
        },
        toAdd() {//组件跳转到添加页面
          this.$router.push('/CustomerAdd');
        },
        handleSizeChange: function (val) {
          this.page.pagesize = val;
          this.searchList();
        },
        handleCurrentChange: function (val) {
          this.page.pagenum = val;
          this.searchList();
        },
        crearUserForm: function () {
          //清空数据
        },
        searchList: function () {//客户列表
          debugger
          this.$http.post("/customer/list/" + this.page.pagenum + "/" + this.page.pagesize, this.searchForm).then((res) => {
            this.customerList = res.data.result.list;
            this.total = res.data.result.total;
          });
        },
        //回显
        getCustomer: function (row) {
          let id = row.id;
          //跳转路由后查询显示
          this.$router.push('/CustomerUpdate?id=' + id);
        },
        del: function (row) {
          this.$http.delete("/customer/del/" + row.id).then((res) => {  //获取当前id
            if (res.data.success) {
              this.$message.success(res.data.message);
              this.searchList();
            } else {
              this.$message.error(res.data.message);
            }
          })
        },
        getlinkman: function (row) {
          let id = row.id;
          //跳转路由后查询显示
          this.$router.push('/link?id=' + id);
        }
      },
      mounted(){
          debugger
          this.searchList();
      }
    }
</script>

<style scoped>
  .box-card2{/*搜索框的样式*/
    height: 80px;
    border-radius: 40px;
  }
  .box-card{/*列表的样式*/
    border-radius: 30px;
  }
  .btn{/*按钮的圆角样式*/
    border-radius: 30px;
  }
</style>
